A type is how Python represents
different types of data. In this video, we will discuss
some widely used types in Python. You can have different types in Python. They can be integers like 11, real numbers
like 21.213, they can even be words. Integers, real numbers, and words can
be expressed as different data types. The following chart summarizes three
data types for the last examples. The first column indicates the expression. The second column indicates the data type. We can see the actual data type in
Python by using the type command. We can have int, which stands for
an integer and float that stands for float, essentially a real number. The type string is
a sequence of characters. Here are some integers. Integers can be negative or positive. It should be noted that there is a finite
range of integers but it is quite large. Floats are real numbers. They include the integers but
also numbers in between the integers. Consider the numbers between 0 and 1. We can select numbers in between them. These numbers are floats. Similarly, consider the numbers
between 0.5 and 0.6. We can select numbers in between them. These are floats as well. We can continue the process zooming in for
different numbers. Of course there is a limit but
it is quite small. You can change the type of the expression
in Python, this is called typecasting. You can convert an int to a float. For example, you can convert or
cast the integer 2 to a float 2.0. Nothing really changes, if you cast a
float to an integer, you must be careful. For example, if you cast the float 1.1
to 1, you will lose some information. If a string contains an integer value,
you can convert it to int. If we convert a string that contains
a non-integer value, we get an error. Check out more examples in the lab. You can convert an int to a string or
a float to a string. Boolean is another
important type in Python. A Boolean can take on two values. The first value is True,
just remember we use an uppercase T. Boolean values can also be
False with an uppercase F. Using the type command on a Boolean value,
we obtain the term bool. This is short for Boolean,
if we cast a Boolean True to an integer or float, we will get a 1. If we cast a Boolean False to
an integer or float, we get a 0. If you cast a 1 to a Boolean,
you get a True. Similarly, if you cast a 0 to a Boolean,
you get a False. Check the labs for more examples or check Python.org for
other kinds of types in Python. (Music)